﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;

namespace CSMF
{
    public partial class Login : System.Web.UI.Page
    {

        
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void loginBtn_Click(object sender, EventArgs e)
        {
            var authenticationService = new AuthenticationService();
            var userRegistrationSerivce = new UserRegistrationService();
            var userService = new UserService();

            lblMsg.Visible = false;
            if(userRegistrationSerivce.ValidateCustomer(this.LoginName.Text, this.Password.Text))
            {
                var user = userService.GetCustomerByUsername(this.LoginName.Text);

                //sign in new customer
                authenticationService.SignIn(user, true);

                Response.Redirect("index.aspx");
            }
            else
            {
                
                lblMsg.Visible = true;
                lblMsg.Text = "登录失败";
            }
        }
    }
}